{
    //蛇类
    class Snake {
        constructor(options) {
            this.snakeId = utils.randomString(10);
            this.bodyColor = options.bodyColor; //蛇身体的颜色
            this.orientation = options.orientation; //蛇的方向
            this._isDie = false; //判断蛇是否死亡
            this.unitSize = 4; //单位大小
            this.speed = 100; //单位毫秒
            //初始化头部的坐标
            this.bodies = [
                {
                    x: 0,
                    y: 0
                }
            ];
        }

        //设置蛇头部的初始坐标，这个function会清空身体。
        setInitCoor(coor) {
            this.bodies = [{
                x: coor.x,
                y: coor.y
            }];
        }

        //吃东西
        eat(coor) {
            this.bodies.unshift(coor);
        }

        //移动头部到指定的坐标，移动头部并且同时计算各个身体的坐标
        moveTo(coor) {

        }

        //往左边移动一个单位
        moveLeft() {
            this.moveBody("left");
        }

        //往右边移动一个单位
        moveRight() {
            this.moveBody("right");
        }

        //往上边移动一个单位
        moveUp() {
            this.moveBody("up");
        }

        //往下边移动一个单位
        moveDown() {
            this.moveBody("down");
        }

        moveBody(direction) {
            if ( this._isDie ) return false;
            let head = {
                x: this.bodies[0].x,
                y: this.bodies[0].y
            }
            this.bodies.pop();
            switch (direction) {
                case "up":
                    this.bodies.unshift({
                        x: head.x,
                        y: head.y - this.unitSize
                    });
                break;
                case "down":
                    this.bodies.unshift({
                        x: head.x,
                        y: head.y + this.unitSize
                    });
                break;
                case "left":
                    this.bodies.unshift({
                        x: head.x - this.unitSize,
                        y: head.y
                    });
                break;
                case "right":
                    this.bodies.unshift({
                        x: head.x + this.unitSize,
                        y: head.y
                    });
                break;
            }
        }

        //死亡
        die() {
            this._isDie = true;
            this.bodies = [];
        }

        //获取身体坐标组
        getBodyCoors() {
            return this.bodies.slice(0);
        }

        //获取身体颜色
        getBodyColor() {
            return this.bodyColor;
        }
    }

    window.Snake = Snake;
}